package cn.kgm.result;

import com.alibaba.fastjson.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author kappi
 * @kapi #技术改变自己#
 * @PACKAGE: cn.kgm.result.Result
 * @EMAIL: Yolo.jk@qq.com
 * @DATE: 2023/4/16 15:53
 * @DAY_NAME_SHORT: 周日
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    private String name;

    private LocalDateTime dateTime;

    private String message;


    public static TextWebSocketFrame fail(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(Result.builder()
                .name("System Message")
                .dateTime(LocalDateTime.now())
                .message(message)
                .build()));
    }

    public static TextWebSocketFrame success(String message) {
        return new TextWebSocketFrame(JSON.toJSONString(Result.builder()
                .name("System Message")
                .dateTime(LocalDateTime.now())
                .message(message)
                .build()));
    }

    public static TextWebSocketFrame success(String nickname, String message) {
        return new TextWebSocketFrame(JSON.toJSONString(Result.builder()
                .name(nickname)
                .dateTime(LocalDateTime.now())
                .message(message)
                .build()));
    }

}
